package com.coordinate.servlets;
import com.oreilly.servlet.multipart.FilePart;
import com.oreilly.servlet.multipart.MultipartParser;
import com.oreilly.servlet.multipart.Part;
import com.google.appengine.api.datastore.Blob;

import com.coordinate.servlets.VoiceMessage;
import com.coordinate.db.*;
import com.devicemantra.coordinate.ds.tests.PMF;

import java.io.IOException;
import java.io.InputStream;
import java.util.Collection;
import java.util.Iterator;

import javax.jdo.PersistenceManager;
import javax.jdo.Query;
import javax.servlet.http.*;

import org.apache.commons.io.IOUtils;

@SuppressWarnings("serial")
public class ShowAllVoiceMessages extends HttpServlet {
	public void doGet(HttpServletRequest req, HttpServletResponse resp)
			throws IOException {
		
		resp.setContentType("text/html");
		resp.getWriter().println("<html>");
		resp.getWriter().println("<title>The Message List</title>");
		resp.getWriter().println("<body>");
		
		
		PersistenceManager lPm = PMF.get().getPersistenceManager();
		
		try
		{
			
			Query lQuery =lPm.newQuery(VoiceMessage.class);
			Collection lList = (Collection )lQuery.execute();
			Iterator lIter = lList.iterator();
			resp.getWriter().println("You have "+ lList.size() + "Voice Messages<br/>");
			resp.getWriter().println("<EMBED SRC=\"http://192.168.1.230:8888/chink.wav?i=100\""+ " width=\"128\" height=\"20\" controls=\"consloe\""+">");
			
			while(lIter.hasNext())
			{
				VoiceMessage lVm = (VoiceMessage)lIter.next();
				resp.getWriter().println("Voice Message :"+ lVm.getFileName()+"<br/>");
				resp.getWriter().println("<EMBED SRC=http://192.168.1.230:8888"+"/GetVm.wav?vm_key="+lVm.getKey()+" width=\"128\" height=\"20\" controls=\"consloe\""+">");
				//resp.getWriter().println("<a href="+"/GetVmMessage?vm_key="+lVm.getKey()+" >"+lVm.getFileName()+" </a>");
			}
	
		}
		catch(Exception e)
		{
		  e.printStackTrace();	
		}
		finally
		{
			lPm.close();
		}
		resp.getWriter().println("</body></html>");
		//resp.getWriter().close();
	}
		
	
}

